<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<!-- datagrid数据表格 -->
<table id="myDatagridarticle"></table>
<!-- datagrid数据表格==END== -->

<!-- 按钮 -->
<div id="myBtnDivarticle">
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="toOpenAdd()">添加</a>&nbsp;&nbsp;
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-blank',plain:true" onclick="resetIndexDB()">重置索引库</a>
    &nbsp;&nbsp;&nbsp;&nbsp;
    <%--搜索框--%>
    <input id="articleKeywords"/>
    <div id="articleKeywordsDiv" style="width:120px">
        <div data-options="name:'all',iconCls:'icon-blank'">高级检索</div>
    </div>
    <%--搜索框--%>


</div>
<!-- 按钮===END=== -->


<!-- 添加对话框 -->
<div id="myAddDialogDivarticle" class="easyui-dialog" data-options="closed:true, width: 600, height: 400" >
    <form method="post" id="myFormarticle" enctype="multipart/form-data">
        文章标题：<input type="text" name="articleName"/><br/><br/>
        文章插图：<input type="file" name="picture" /><br/><br/>
        文章内容：<input type="text" name="articleContent"/><br/><br/>
        上师法号：<select name="guruId" id="guruNicknameSelect"></select><br/><br/><br/><br/>
        <input type="button" value="添加" onclick="doAddSubmit()">
    </form>
</div>
<!-- 添加对话框===END=== -->

<script type="text/javascript">
    $(function (){

        /* datagrid展示数据 */
        $("#myDatagridarticle").datagrid({
            url:'${pageContext.request.contextPath}/article/showAll',
            pagination:true,
            columns:[[
                {field:'articleId',title:'文章编号'},
                {field:'articleName',title:'文章标题'},
                {field:'articleImage',title:'文章插图',formatter: function(value,row,index){
                      return " <img src='${pageContext.request.contextPath}"+value+" 'width='30' height='30' />"
                   }
                },
                {field:'articleContent',title:'文章内容'},
                {field:'guruNickname',title:'上师法号'},
                {field:'articleDate',title:'发布日期'}
            ]],
            toolbar: '#myBtnDivarticle',
        });
        /* datagrid展示数据  结束 */


        /*搜索框*/
        $('#articleKeywords').searchbox({
            searcher:function(value,name){
                $("#myDatagridarticle").datagrid("reload", {"articleKeywords": value});
            },
            menu:'#articleKeywordsDiv',
            prompt:'请输入查询内容'
        });
        /*搜索框*/
    });



    /* 添加文章 */
    function toOpenAdd(){
        $('#myAddDialogDivarticle').dialog("open");
        $.ajax({
            url:"${pageContext.request.contextPath}/guru/selectAll",
            type:"post",
            dataType:"JSON",
            success:function(data){
                if(data.flag){
                    $.each(data.cmfzGurus, function (index, item) {
                        var option=$("<option value='"+item.guruId+"'>"+item.guruName+"</option>");
                        $("#guruNicknameSelect").append(option);
                    })
                }
            }
        });
    };

    function doAddSubmit(){

        $('#myFormarticle').form('submit', {
            url:"${pageContext.request.contextPath}/article/add",
            success:function(data){
                var data=JSON.parse(data);
                if(data.flag){
                    $('#myAddDialogDivarticle').dialog("close");
                    $("#myDatagridarticle").datagrid("reload");
                }else{
                    $.messager.alert('提示框','添加失败，请确认！','warning');
                }

            }
        });
    }
    /* 添加文章 */

    /*重置索引库*/
    function resetIndexDB(){
        $.ajax({
            url:"${pageContext.request.contextPath}/article/resetIndexDB",
            type:"post",
            dataType:"JSON",
            success:function(data){
                if(data.flag){
                    $.messager.alert('提示框','重置成功！，请确认！','warning');
                }else{
                    $.messager.alert('提示框','重置失败！，请确认！','warning');
                }
            }
        });
    };
    /*重置索引库*/

</script>